﻿package mortal.game.view.friendBless.view.renderer
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.flowerSend.data.*;
    import mortal.game.view.friendBless.view.data.*;
    import mortal.game.view.friendBless.view.view.*;
    import mortal.mvc.core.*;

    public class FriendBlessCellRenderer extends GCellRenderer
    {
        private var _bg:ScaleBitmap;
        private var _headSpr:FriendBlessHeadSpr;
        private var _roleName:GTextFiled;
        private var _exp:GTextFiled;
        private var _lingqi:GTextFiled;
        private var _bless:GButton;
        private var _sendFlower:GButton;
        private var _friendCongratulateData:FriendCongratulateData;

        public function FriendBlessCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 744 + 6 - 120, 49, this, ImagesConst.RankingListBg);
            this._headSpr = UICompomentPool.getUICompoment(FriendBlessHeadSpr);
            this._headSpr.x = 1;
            this._headSpr.y = 4;
            this.addChild(this._headSpr);
            this._roleName = UIFactory.gTextField("人物名字七个字", 98 - 24 - 10, 20 - 6, 88, 20, this, GlobalStyle.textFormatBai.center());
            this._exp = UIFactory.gTextField("经验    999", 397 - 108 - 67, 20 - 6, 120, 20, this, GlobalStyle.textFormatBai);
            this._lingqi = UIFactory.gTextField("金币    999", 485 - 108 - 67, 20 - 6, 120, 20, this, GlobalStyle.textFormatBai);
            this._bless = UIFactory.gButton("祝福", 590 - 2 - 100 + 35, 14 - 2, 54, 26, this, "RedButton");
            this._sendFlower = UIFactory.gButton("送花", 654 + 2 - 100, 14 - 2, 54, 26, this, "RedButton");
            this._sendFlower.visible = false;
            this._bless.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._sendFlower.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            Dispatcher.addEventListener(EventName.FriendBlessBtnStateUpdate, this.onBlessBtnStateUpdate);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:Object = null;
            super.data = param1;
            this._friendCongratulateData = param1 as FriendCongratulateData;
            if (this._friendCongratulateData)
            {
                this._headSpr.data = this._friendCongratulateData.miniPlayer;
                this._roleName.text = this._friendCongratulateData.miniPlayer.name;
                _loc_2 = QuestionCopyConfig.instance().getRewardInfoByTypeAndLevel(6, this._friendCongratulateData.miniPlayer.level);
                if (_loc_2)
                {
                    this._exp.htmlText = HTMLUtil.addColor("经验    ", GlobalStyle.colorHuang2) + _loc_2.experFixed;
                    this._lingqi.htmlText = HTMLUtil.addColor("金币    ", GlobalStyle.colorLan) + _loc_2.vitalEnergy;
                }
                if (this._friendCongratulateData.hasBlessed)
                {
                    this._bless.filters = [FilterConst.colorFilter2];
                    this._bless.mouseEnabled = false;
                }
                else
                {
                    this._bless.filters = [];
                    this._bless.mouseEnabled = true;
                }
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:FlowerSendData = null;
            if (event.target == this._bless)
            {
                GameProxy.friend.congratulate([this._friendCongratulateData.miniPlayer.entityId.id]);
            }
            if (event.target == this._sendFlower)
            {
                _loc_2 = new FlowerSendData();
                _loc_2.toPlayer = this._friendCongratulateData.miniPlayer;
                Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerOpenWin, _loc_2));
            }
            return;
        }// end function

        private function onBlessBtnStateUpdate(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SMiniPlayer;
            if (_loc_2.entityId.id == this._friendCongratulateData.miniPlayer.entityId.id)
            {
                this._bless.filters = [FilterConst.colorFilter2];
                this._bless.mouseEnabled = false;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._bg.dispose();
            this._bg = null;
            this._headSpr.dispose();
            this._headSpr = null;
            this._roleName.dispose();
            this._roleName = null;
            this._exp.dispose();
            this._exp = null;
            this._lingqi.dispose();
            this._lingqi = null;
            this._bless.dispose();
            this._bless = null;
            this._sendFlower.dispose();
            this._sendFlower = null;
            this._friendCongratulateData = null;
            Dispatcher.removeEventListener(EventName.FriendBlessBtnStateUpdate, this.onBlessBtnStateUpdate);
            return;
        }// end function

    }
}
